<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
  for (let i = 0;i < 10; i++) {
    let a = document.createElement('a');
    a.innerHTML = i +'<br>';
    a.addEventListener('click', function(e) {
      e.preventDefault();
      alert(i);
    })
    document.body.appendChild(a);
  }
</script>

</body>
</html>
